package cn.wolfcode.web.controller;

import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISystemDictionaryService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    @RequestMapping("/list")
    @RequiredPermission(name = "字典目录页面" , expression = "systemDictionary:list")
    public String list(QueryObject qo, Model model) {
        PageInfo pageInfo = systemDictionaryService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "systemDictionary/list";
    }


    @RequestMapping("/delete")
    @RequiredPermission(name = "字典目录删除" , expression = "systemDictionary:delete")
    public String delete(Long id) {
        if (id != null) {
            systemDictionaryService.deleteSystemDictionary(id);
        }
        return "redirect:/systemDictionary/list";
    }


    @RequestMapping("/saveOrUpdate")
    @RequiredPermission(name = "字典目录新增或修改" , expression = "systemDictionary:saveOrUpdate")
    public String saveOrUpdate(SystemDictionary systemDictionary){
        if(systemDictionary.getId() != null){
            systemDictionaryService.updateSystemDictionary(systemDictionary);
        }else{
            systemDictionaryService.insertSystemDictionary(systemDictionary);
        }
        return "redirect:/systemDictionary/list";
    }
}
